// component/common/copyright/copyright.js
var app = getApp()
Component({
  properties: {

  },
  data: {
    bannerlist:[],
    currentSwiper: 0,
    swiperError: 0,
    preIndex: 0,
    theme:app.theme
  },
  attached(){
    this.setData({
      bannerlist:app.data.bannerlist
    })
  },
  methods: {
    
    // 获取轮播
    getbanners() {
      let that = this;
      
      let shop = app.functions.getLocalStorage("shop");
      if (app.functions.isEmpty(shop)) return;
      let params = {
        centerId: shop.centreId,
        supplyChannel: app.supplyChannel
      }
      app.api.banners(params, (response) => {
        if(response.data.length>0){
          that.setData({
            bannerlist: response.data
          })
        }
      }, (e) => {
        app.functions.showToast(e.msg);
      })
    },
    changefinishSwip: function (detail) {
      this.setData({
        currentSwiper: detail.detail.current
      })
      if (detail.detail.current == 0) {
        this.setData({
          swiperError: this.data.swiperError + 1
        })
        if (this.data.swiperError >= 3) {
          this.setData({
            currentSwiper: this.data.preIndex,
            swiperError: 0
          });
        }
      }else{
        this.setData({
          preIndex: detail.detail.current,
          currentSwiper: detail.detail.current,
          swiperError: 0
        });
      }
    },
    // 配置轮播跳转
    topage(e){
      let index=e.currentTarget.dataset.index;
      let item=this.data.bannerlist[index];
      wx.navigateTo({
        url: '/'+item.appLike
      })
    }
  }

})
